<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: space_mtag.php 10777 2008-12-22 06:44:14Z liguode $
*/

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}

include_once(S_ROOT.'./site/libs/func_util.php');
include_once(S_ROOT.'./source/function_cp.php');
include_once(S_ROOT.'./site/libs/func_model.php');

//是否公开
if(empty($isinvite) && empty($_SCONFIG['networkpublic'])) {
	checklogin();//需要登录
}

//获取空间
if($uid) {
	$space = getspace($uid, 'uid', 0);
} elseif ($username) {
	$space = getspace($username, 'username', 0);
} elseif ($domain) {
	$space = getspace($domain, 'domain', 0);
} else {
	if(empty($_SGLOBAL['supe_uid'])) {
		if ($do != 'mtag') {
			ssetcookie('_refer', rawurlencode($_SERVER['REQUEST_URI']));
			showmessage('to_login', 'do.php?ac='.$_SCONFIG['login_action']);
		}
	} else {
		$space = getspace($_SGLOBAL['supe_uid'], 'uid', 0);
	}
}

$page = empty($_GET['page'])?1:intval($_GET['page']);
if (empty($_GET['view']) || $_GET['view'] == 'mine') 
		$_GET['view'] = 'me';

if($_GET['view'] == 'me') {
			
		$perpage = 20;
		$start = ($page-1)*$perpage;
		
		//检查开始数
		ckstart($start, $perpage);

		$list = $tagids = array();
		
		//$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('tagspace')." main WHERE main.uid='$_SGLOBAL[supe_uid]'"),0);
        //echo $count;
        $uid = empty($_GET['uid'])?$_SGLOBAL['supe_uid']:intval($_GET['uid']);
		if($uid) {
			$query = $_SGLOBAL['db']->query("SELECT main.*,field.* FROM ".tname('tagspace')." main 
			LEFT JOIN ".tname('mtag')." field ON field.tagid=main.tagid 
			WHERE main.uid='$uid' AND field.tagtype=1 ORDER BY main.grade DESC LIMIT $start,$perpage");

			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				realname_set($value['uid'], $value['username']);
				if(empty($value['pic'])) {
					$value['pic'] = 'image/nologo.jpg';
				}
				if($value['grade']>-2) {
					$tagids[$value['tagid']] = $value['tagid'];//已经批准的群组
				}
				$list[] = $value;
			}
		}
        $theurl = "site.php?uid=$uid&do=my_profile&view=me";
		//分页
		$multi = multi($count, $perpage, $page, $theurl);
		
		//最新话题
		$threadlist = array();
		if($tagids) {
			$query = $_SGLOBAL['db']->query("SELECT main.*,field.tagname,field.membernum,field.fieldid FROM ".tname('thread')." main
				LEFT JOIN ".tname('mtag')." field ON field.tagid=main.tagid
				WHERE main.tagid IN (".simplode($tagids).") AND field.tagtype=1
				ORDER BY main.lastpost DESC
				LIMIT 0,10");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				realname_set($value['uid'], $value['username']);
				$threadlist[] = $value;
			}
		}

		realname_get();

		include_once template("site/tpl/uc_myprofile");
		exit;
	} elseif($_GET['view'] == 'hot') {
		$list = $pthreadlist = array();
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mtag')." WHERE tagtype=1 ORDER BY spotcnt, membernum DESC LIMIT 0,2");
		
        while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			if(empty($value['pic'])) {
				$value['pic'] = 'image/nologo.jpg';
			}
			$list[] = $value;
		}

		include_once template("site/tpl/uc_hotprofile");
		exit;
	} elseif($_GET['view'] == 'spot') {
		$proflist = $pthreadlist = array();
		$query = $_SGLOBAL['db']->query("SELECT tagid,tagname,membernum,pic FROM ".tname('mtag')." WHERE tagtype=1 ORDER BY spotcnt, membernum DESC LIMIT 0,2");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			if(empty($value['pic'])) {
				$value['pic'] = 'image/nologo.jpg';
			}
			$proflist[] = $value;
		}

		include_once template("site/tpl/uc_myspot");
		exit;
	}
?>
